package com.sgb.kjwl.view.ui.activity.business;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMemberDetailBinding;
import com.sgb.kjwl.view.ui.fragment.business.MemberDetailFragment;
import com.sgb.kjwl.view.ui.fragment.business.MemberInfoFragment;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;

public class MemberDetailActivity extends AppActivity {
    private ActivityMemberDetailBinding binding;

    private String[] titles = {"企业信息", "企业详情"};
    private ArrayList<Fragment> mFragments;
    private MemberInfoFragment upFragment;
    private MemberDetailFragment downFragment;
    private String id;

    public static void start(Context context) {
        start(context, null);
    }

    public static void start(Context context, String id) {
        Intent intent = new Intent();
        intent.setClass(context, MemberDetailActivity.class);
        intent.putExtra("id", id);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        id = getIntent().getStringExtra("id");

        binding = DataBindingUtil.setContentView(MemberDetailActivity.this, R.layout.activity_member_detail);
        binding.backView.setOnClickListener(this);
       /* binding.rightView.setOnClickListener(this);
        binding.rightView.setVisibility(View.GONE);*/
        mFragments = new ArrayList<Fragment>();
        upFragment = MemberInfoFragment.newInstance(id);
        downFragment = MemberDetailFragment.newInstance(id);
        mFragments.add(upFragment);
        mFragments.add(downFragment);
        SlidingFragmentPagerAdapter mAdapetr = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.viewpager.setAdapter(mAdapetr);
        binding.viewpager.setOffscreenPageLimit(1);
        binding.tablayout.setupWithViewPager(binding.viewpager);

        binding.tablayout.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition()==0){
                }else {
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_view:
                finish();
                break;
        }
    }
}
